<?php
/**
 * Dirox Framework
 * Copyright (C) 2005 - 2007 Dirox / Synexser
 * 
 * All rights reserved.
 */

require_once ("DRX_UrlParser.php");

class DRX_MultiLanguage {
	function DRX_MultiLanguage($lang="fr")
	{
		if(!isset($_COOKIE["lang_default"]))
		{
			setcookie("lang_default", $lang, time() + 3600*24*30,str_replace("/index.php","",$_SERVER['PHP_SELF']));
		}
	}

	function GetLanguage()
	{
		if(isset($_COOKIE["lang_default"]))
		{
			return $_COOKIE["lang_default"];
		}
	}

	function SetChangeLanguage($lang)
	{
		setcookie("lang_default", $lang, time() + 3600*24*30,str_replace("/index.php","",$_SERVER['PHP_SELF']));
	}

	function ShowLinkLanguage($arrLang) {
		$sLink = "";
		$root_path = str_replace("/index.php","",$_SERVER['PHP_SELF']);
		$objUrl = new DRX_UrlParser();
		$root_path = $objUrl->GetRootPath();
		$page_link = $objUrl->UrlToModrewrite($_SERVER['QUERY_STRING']);
		//get clean URL
		while (list($key, $val) = each($arrLang)) {
			$page_link = str_replace("setlang/".$key, "", $page_link);
		}
		reset($arrLang);
		//show link
		while (list($key, $val) = each($arrLang)) {
			$val_href = $root_path.$page_link . '/setlang/'.$key;
			$sLink.= '<a href="'.str_replace("//","/",$val_href).'">'.$val.'</a>&nbsp;|&nbsp;';
		}
		unset($objUrl);
		return "|&nbsp;".$sLink;
	}
}
?>